﻿using System;
using Com.PhilChuang.Utils;
using Com.PhilChuang.Pmvp.Ui.Views;

namespace Com.PhilChuang.Pmvp.Ui.Presenters
{
	public class SendFeedbackPresenter : AbstractEmailSendingPresenter<ISendFeedbackView>
	{
		#region Constants
		private const String SAVE_FILE = "SendFeedback.txt";
		#endregion

		#region Instance variables
		private readonly SendFeedbackPresenterConfig m_Config;
		#endregion

		#region Constructors
		public SendFeedbackPresenter () : this (AppServiceLocator.Instance.GetImpl<SendFeedbackPresenterConfig> (), AppServiceLocator.Instance.GetImpl<ISendFeedbackView> ())
		{
		}

		public SendFeedbackPresenter (ISendFeedbackView view) : this (AppServiceLocator.Instance.GetImpl<SendFeedbackPresenterConfig> (), view)
		{
		}

		public SendFeedbackPresenter (SendFeedbackPresenterConfig config, ISendFeedbackView view) : base (view)
		{
			config.ThrowIfNull ("config");
			m_Config = config;
		}
		#endregion

		#region AbstractEmailSendingPresenter implementation
		protected override string Prompt { get { return "How can {0} be improved?".FormatWith (m_Config.VersionInfo.ProductName); } }

		protected override bool Validate ()
		{
			if (!base.Validate ())
				return false;

			if (m_UserText.IsNullOrEmptyOrBlank ())
			{
				View.DisplayMessage ("Please enter your feedback.", "Error");
				return false;
			}

			return true;
		}

		protected override String EmailDestination { get { return m_Config.FeedbackEmailAddress; } }
		protected override String EmailSubject { get { return m_Config.FeedbackEmailSubject; } }
		protected override string EmailBody { get { return m_Config.FeedbackEmailBodyFormat.FormatWith (m_UserText); } }

		protected override string SaveFilename { get { return SAVE_FILE; } }
		#endregion
	}
}
